//引入API里面请求函数
import { reqCategoryList, reqBannerList, reqFloorList } from "@/api";
//每一个小仓库需要有四样:state|mutations|actions|getters
const state = {
    //小仓库home存储数据的地方，用来存储商品分类的数据
    categoryList: [],
    bannerList: [],
    floorList:[]
};
const mutations = {
    //state:当前仓库state的数据   categoryList：commit提交过来的数据
    GETCATEGORYLIST(state, categoryList) {
        state.categoryList = categoryList;
    },
    BANNERLIST(state, bannerList) {
        state.bannerList = bannerList;
    },
    FLOORLIST(state,floorList){
        state.floorList = floorList;
    }

};
//actions:书写逻辑[IF|书写异步]
const actions = {
    //actions第一个参数:context   第二个参数:组件派发action的时候携带参数
    async getCategoryList({ commit, state, getters, dispatch }) {
        //获取首页商品分类的数据
        let result = await reqCategoryList();
        if (result.code == 200) {
            //提交mutations:让mutation修改仓库里面state数据
            commit('GETCATEGORYLIST', result.data)
        }
    },
    //首页banner轮播图
    async bannerList({ commit, state, dispatch, getters }) {
        //获取banner数据
        let result = await reqBannerList();
        if (result.code == 200) {
            commit('BANNERLIST', result.data);
        }
    },
    //floor数据
    async floorList({ commit, state, dispatch, getters }) {
        let result = await reqFloorList();
        if(result.code==200){
            commit("FLOORLIST",result.data);
        }
    }
};
const getters = {};
//对外暴露小仓库
export default {
    state,
    mutations,
    actions,
    getters
}